import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { VideosValueType } from 'src/redux';

export interface WatchHistory {
  movieName: string; // 观看影片名
  watchDate: Date; // 观看日期
}

export interface WatchState {
  watchHistory: Array<WatchHistory>;
  watchVideo?: VideosValueType;
}

const initialState: WatchState = {
  watchHistory: [
    {
      movieName: 'wss',
      watchDate: new Date(),
    },
  ],
};

export const WatchSlice = createSlice({
  name: 'watch',
  initialState,
  reducers: {
    setHistory(state, action: PayloadAction<WatchHistory>) {
      return { ...state, watchHistory: [action.payload, ...state.watchHistory] };
    },
    setWatchVideo(state, action: PayloadAction<VideosValueType>) {
      return { ...state, watchVideo: action.payload };
    },
  },
});

export const actions = WatchSlice.actions;
